package test;


import static org.junit.Assert.*;
import java.sql.SQLException;
import library.*;

import library.controller.BookController;
import library.entity.Book;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class SystemTestBook{
	private String testingBookName = "testing book item";
	private BookController bookController;
	@Before
	public void setUp() throws SQLException{
		DaoUtil.init();
		bookController = new BookController();
	}
	
	@Test
	public void addBook() throws Exception {
		Book newBook = new Book(testingBookName,1234567);
		Boolean res =  bookController.createNewBook(newBook);
		assertTrue(res);
	}
	
	@Test
	public void checkExistBookID() throws Exception {
		Book bk2 = bookController.getBookById(3);
		assertNotNull(testingBookName, bk2.getName());
	}
	
	@Test
	public void checkNotExistBookID() throws Exception {
		Book notExistBook = bookController.getBookById(-987);
        assertNull(notExistBook);
	}

    @Test
    public void searchBook() throws Exception {
        Book bk = bookController.search("testing book item").get(0);
        assertEquals(bk.getName(), "testing book item");
    }
}
